home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat5 / regcomp.z / regcomp
Encoding:
Text File  |  2002-10-03  |  59.5 KB  |  1,255 lines

  1.  
  2.  
  3.  
  4. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      regcomp - X/Open regular expressions definition and interface
  10.  
  11. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  12.      _NNNN_oooo_tttt_eeee_::::  Two versions of regular expressions are supported:
  13.  
  14.      _oooo    the historical _SSSS_iiii_mmmm_pppp_llll_eeee _RRRR_eeee_gggg_uuuu_llll_aaaa_rrrr _EEEE_xxxx_pppp_rrrr_eeee_ssss_ssss_iiii_oooo_nnnn_ssss, which provide backward
  15.           compatibility, but which will be withdrawn from a future issue of
  16.           this document set
  17.  
  18.      _oooo    the improved internationalised version that complies with the
  19.           ISO/IEC 9945-2: 1993 standard.
  20.  
  21.      The first (historical) version is described as part of the _r_e_g_e_x_p
  22.      function in the _rrrr_eeee_gggg_eeee_xxxx_pppp_((((_5555_)))) man page. The second (improved) version is
  23.      described in this man page.
  24.  
  25.      _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s (REs) provide a mechanism to select specific strings
  26.      from a set of character strings.
  27.  
  28.      Regular expressions are a context-independent syntax that can represent a
  29.      wide variety of character sets and character set orderings, where these
  30.      character sets are interpreted according to the current locale. While
  31.      many regular expressions can be interpreted differently depending on the
  32.      current locale, many features, such as character class expressions,
  33.      provide for contextual invariance across locales.
  34.  
  35.      The Basic Regular Expression (BRE) notation and construction rules in _bbbb_rrrr_eeee
  36.      apply to most utilities supporting regular expressions.  Some utilities,
  37.      instead, support the Extended Regular Expressions (ERE) described in _eeee_rrrr_eeee;
  38.      any exceptions for both cases are noted in the descriptions of the
  39.      specific utilities using regular expressions. Both BREs and EREs are
  40.      supported by the Regular Expression Matching interface in the _rrrr_eeee_gggg_cccc_mmmm_pppp_((((_)))),
  41.      _rrrr_eeee_gggg_eeee_xxxx_eeee_cccc_((((_)))) and related functions.
  42.  
  43. RRRReeeegggguuuullllaaaarrrr EEEExxxxpppprrrreeeessssssssiiiioooonnnn DDDDeeeeffffiiiinnnniiiittttiiiioooonnnnssss
  44.      For the purposes of this section, the following definitions apply:
  45.  
  46.      _eeee_nnnn_tttt_iiii_rrrr_eeee _rrrr_eeee_gggg_uuuu_llll_aaaa_rrrr _eeee_xxxx_pppp_rrrr_eeee_ssss_ssss_iiii_oooo_nnnn
  47.  
  48.      The concatenated set of one or more BREs or EREs that make up the pattern
  49.      specified for string selection.
  50.  
  51.      _mmmm_aaaa_tttt_cccc_hhhh_eeee_dddd
  52.  
  53.           A sequence of zero or more characters is said to be matched by a BRE
  54.           or ERE when the characters in the sequence correspond to a sequence
  55.           of characters defined by the pattern.
  56.  
  57.           Matching is based on the bit pattern used for encoding the
  58.           character, not on the graphic representation of the character. This
  59.           means that if a character set contains two or more encodings for a
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  71.  
  72.  
  73.  
  74.           graphic symbol, or if the strings searched contain text encoded in
  75.           more than one codeset, no attempt is made to search for any other
  76.           representation of the encoded symbol. If that is required, the user
  77.           can specify equivalence classes containing all variations of the
  78.           desired graphic symbol.
  79.  
  80.           The search for a matching sequence starts at the beginning of a
  81.           string and stops when the first sequence matching the expression is
  82.           found, where _f_i_r_s_t is defined to mean ``begins earliest in the
  83.           string''. If the pattern permits a variable number of matching
  84.           characters and thus there is more than one such sequence starting at
  85.           that point, the longest such sequence will be matched. For example:
  86.           the BRE bb* matches the second to fourth characters of abbbc, and
  87.           the ERE (wee|week)(knights|night) matches all ten characters of
  88.           weeknights.
  89.  
  90.           Consistent with the whole match being the longest of the leftmost
  91.           matches, each subpattern, from left to right, matches the longest
  92.           possible string. For this purpose, a null string is considered to be
  93.           longer than no match at all. For example, matching the BRE \(.*\).*
  94.           against abcdef, the subexpression (\1) is abcdef, and matching the
  95.           BRE \(a*\)* against bc, the subexpression (\1) is the null string.
  96.  
  97.           It is possible to determine what strings correspond to
  98.           subexpressions by recursively applying the leftmost longest rule to
  99.           each subexpression, but only with the proviso that the overall match
  100.           is leftmost longest. For example, matching \(ac*\)c*d[ac]*\1 against
  101.           acdacaaa matches acdacaaa (with \1=a); simply matching the longest
  102.           match for \(ac*\) would yield \1=ac, but the overall match would be
  103.           smaller (acdac). Conceptually, the implementation must examine every
  104.           possible match and among those that yield the leftmost longest total
  105.           matches, pick the one that does the longest match for the leftmost
  106.           subexpression and so on. Note that this means that matching by
  107.           subexpressions is context-dependent: a subexpression within a larger
  108.           RE may match a different string from the one it would match as an
  109.           independent RE, and two instances of the same subexpression within
  110.           the same larger RE may match different lengths even in similar
  111.           sequences of characters. For example, in the ERE (a.*b)(a.*b), the
  112.           two identical subexpressions would match four and six characters,
  113.           respectively, of accbaccccb.
  114.  
  115.           When a multi-character collating element in a bracket expression is
  116.           involved, the longest sequence will be measured in characters
  117.           consumed from the string to be matched; that is, the collating
  118.           element counts not as one element, but as the number of characters
  119.           it matches.
  120.  
  121.      _BBBB_RRRR_EEEE _((((_EEEE_RRRR_EEEE_)))) _mmmm_aaaa_tttt_cccc_hhhh_iiii_nnnn_gggg _aaaa _ssss_iiii_nnnn_gggg_llll_eeee _cccc_hhhh_aaaa_rrrr_aaaa_cccc_tttt_eeee_rrrr
  122.  
  123.           A BRE or ERE that matches either a single character or a single
  124.           collating element.
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  137.  
  138.  
  139.  
  140.           Only a BRE or ERE of this type that includes a bracket expression
  141.           can match a collating element.
  142.  
  143.           The definition of _s_i_n_g_l_e character has been expanded to include also
  144.           collating elements consisting of two or more characters; this
  145.           expansion is applicable only when a bracket expression is included
  146.           in the BRE or ERE.  An example of such a collating element may be
  147.           the Dutch ij, which collates as a y.  In some encodings, a ligature
  148.           ``i with j'' exists as a character and would represent a single-
  149.           character collating element. In another encoding, no such ligature
  150.           exists, and the two-character sequence ij is defined as a multi-
  151.           character collating element. Outside brackets, the ij is treated as
  152.           a two-character RE and matches the same characters in a string.
  153.           Historically, a bracket expression only matched a single character.
  154.           If, however, the bracket expression defines, for example, a range
  155.           that includes ij, then this particular bracket expression will also
  156.           match a sequence of the two characters i and j in the string.
  157.  
  158.      _BBBB_RRRR_EEEE _((((_EEEE_RRRR_EEEE_)))) _mmmm_aaaa_tttt_cccc_hhhh_iiii_nnnn_gggg _mmmm_uuuu_llll_tttt_iiii_pppp_llll_eeee _cccc_hhhh_aaaa_rrrr_aaaa_cccc_tttt_eeee_rrrr_ssss
  159.  
  160.           A BRE or ERE that matches a concatenation of single characters or
  161.           collating elements.
  162.  
  163.      _iiii_nnnn_vvvv_aaaa_llll_iiii_dddd
  164.  
  165.           This section uses the term _i_n_v_a_l_i_d for certain constructs or
  166.           conditions.  Invalid REs will cause the utility or function using
  167.           the RE to generate an error condition. When _i_n_v_a_l_i_d is not used,
  168.           violations of the specified syntax or semantics for REs produce
  169.           undefined results: this may entail an error, enabling an extended
  170.           syntax for that RE, or using the construct in error as literal
  171.           characters to be matched. For example, the BRE construct \{1,2,3\}
  172.           does not comply with the grammar. A portable application cannot rely
  173.           on it producing an error nor matching the literal characters
  174.           \{1,2,3\}.
  175.  
  176. RRRReeeegggguuuullllaaaarrrr EEEExxxxpppprrrreeeessssssssiiiioooonnnn GGGGeeeennnneeeerrrraaaallll RRRReeeeqqqquuuuiiiirrrreeeemmmmeeeennnnttttssss
  177.      The requirements in this section apply to both basic and extended regular
  178.      expressions.
  179.  
  180.      The use of regular expressions is generally associated with text
  181.      processing.  REs (BREs and EREs) operate on text strings; that is, zero
  182.      or more characters followed by an end-of-string delimiter (typically
  183.      NUL).  Some utilities employing regular expressions limit the processing
  184.      to lines; that is, zero or more characters followed by a newline
  185.      character.  In the regular expression processing described in this
  186.      document, the newline character is regarded as an ordinary character and
  187.      both a period and a non-matching list can match one. The individual man
  188.      pages specify within the individual descriptions of those standard
  189.      utilities employing regular expressions whether they permit matching of
  190.      newline characters; if not stated otherwise, the use of literal newline
  191.      characters or any escape sequence equivalent produces undefined results.
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  203.  
  204.  
  205.  
  206.      Those utilities (like _g_r_e_p) that do not allow newline characters to match
  207.      are responsible for eliminating any newline character from strings before
  208.      matching against the RE. The _r_e_g_c_o_m_p() function (see _rrrr_eeee_gggg_cccc_oooo_mmmm_pppp_((((_3333_GGGG_))))),
  209.      however, can provide support for such processing without violating the
  210.      rules of this section.
  211.  
  212.      The interfaces specified in this document set do not permit the inclusion
  213.      of a NUL character in an RE or in the string to be matched.  If during
  214.      the operation of a standard utility a NUL is included in the text
  215.      designated to be matched, that NUL may designate the end of the text
  216.      string for the purposes of matching.
  217.  
  218.      When a standard utility or function that uses regular expressions
  219.      specifies that pattern matching will be performed without regard to the
  220.      case (upper- or lower-) of either data or patterns, then when each
  221.      character in the string is matched against the pattern, not only the
  222.      character, but also its case counterpart (if any), will be matched. This
  223.      definition of case-insensitive processing is intended to allow matching
  224.      of multi-character collating elements as well as characters. For
  225.      instance, as each character in the string is matched using both its
  226.      cases, the RE [[.Ch.]] when matched against the string char, is in
  227.      reality matched against ch, Ch, cH and CH.
  228.  
  229.      The implementation will support any regular expression that does not
  230.      exceed 256 bytes in length.
  231.  
  232. BBBBaaaassssiiiicccc RRRReeeegggguuuullllaaaarrrr EEEExxxxpppprrrreeeessssssssiiiioooonnnnssss
  233.      _BBBB_RRRR_EEEE_ssss _MMMM_aaaa_tttt_cccc_hhhh_iiii_nnnn_gggg _aaaa _SSSS_iiii_nnnn_gggg_llll_eeee _CCCC_hhhh_aaaa_rrrr_aaaa_cccc_tttt_eeee_rrrr _oooo_rrrr _CCCC_oooo_llll_llll_aaaa_tttt_iiii_nnnn_gggg _EEEE_llll_eeee_mmmm_eeee_nnnn_tttt
  234.  
  235.           A BRE ordinary character, a special character preceded by a
  236.           backslash or a period matches a single character. A bracket
  237.           expression matches a single character or a single collating element.
  238.  
  239.      _BBBB_RRRR_EEEE _OOOO_rrrr_dddd_iiii_nnnn_aaaa_rrrr_yyyy _CCCC_hhhh_aaaa_rrrr_aaaa_cccc_tttt_eeee_rrrr_ssss
  240.  
  241.           An ordinary character is a BRE that matches itself: any character in
  242.           the supported character set, except for the BRE special characters
  243.           listed in _bbbb_rrrr_eeee_ssss_pppp_eeee_cccc.
  244.  
  245.           The interpretation of an ordinary character preceded by a backslash
  246.           (\) is undefined, except for:
  247.  
  248.           1.  the characters ), (, { and }
  249.  
  250.           2.  the digits 1 to 9 inclusive
  251.  
  252.           3.  a character inside a bracket expression.
  253.  
  254.      _BBBB_RRRR_EEEE _SSSS_pppp_eeee_cccc_iiii_aaaa_llll _CCCC_hhhh_aaaa_rrrr_aaaa_cccc_tttt_eeee_rrrr_ssss
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  269.  
  270.  
  271.  
  272.           A _B_R_E _s_p_e_c_i_a_l _c_h_a_r_a_c_t_e_r has special properties in certain contexts.
  273.           Outside those contexts, or when preceded by a backslash, such a
  274.           character will be a BRE that matches the special character itself.
  275.           The BRE special characters and the contexts in which they have their
  276.           special meaning are:
  277.  
  278.      ....[[[[\\\\  The period, left-bracket and backslash is special except when used
  279.           in a bracket expression. An expression containing a _[[[[ that is not
  280.           preceded by a backslash and is not part of a bracket expression
  281.           produces undefined results.
  282.  
  283.      ****    The asterisk is special except when used:
  284.  
  285.           o   in a bracket expression
  286.  
  287.           o   as the first character of an entire BRE (after an initial ^,
  288.               if any)
  289.  
  290.           o   as the first character of a subexpression (after an initial ^,
  291.               if any).
  292.  
  293.      ^^^^    The circumflex is special when used:
  294.  
  295.           o   as an anchor
  296.  
  297.           o   as the first character of a bracket expression.
  298.  
  299.      $$$$    The dollar sign is special when used as an anchor.
  300.  
  301.      _PPPP_eeee_rrrr_iiii_oooo_dddd_ssss _iiii_nnnn _BBBB_RRRR_EEEE_ssss
  302.  
  303.           A period (_....), when used outside a bracket expression, is a BRE that
  304.           matches any character in the supported character set except NUL.
  305.  
  306.  
  307.      _RRRR_EEEE _BBBB_rrrr_aaaa_cccc_kkkk_eeee_tttt _EEEE_xxxx_pppp_rrrr_eeee_ssss_ssss_iiii_oooo_nnnn
  308.  
  309.      A bracket expression (an expression enclosed in square brackets, [ ]) is
  310.      an RE that matches a single collating element contained in the non-empty
  311.      set of collating elements represented by the bracket expression.
  312.  
  313.      The following rules and definitions apply to bracket expressions:
  314.  
  315.  
  316.      1.   A _b_r_a_c_k_e_t _e_x_p_r_e_s_s_i_o_n is either a matching list expression or a non-
  317.           matching list expression. It consists of one or more expressions:
  318.           collating elements, collating symbols, equivalence classes,
  319.           character classes or range expressions. Portable applications must
  320.           not use range expressions, even though all implementations support
  321.           them. The right-bracket (]) loses its special meaning and represents
  322.           itself in a bracket expression if it occurs first in the list (after
  323.           an initial circumflex (^), if any). Otherwise, it terminates the
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  335.  
  336.  
  337.  
  338.           bracket expression, unless it appears in a collating symbol (such as
  339.           [.].]) or is the ending right-bracket for a collating symbol,
  340.           equivalence class or character class. The special characters:
  341.  
  342.           .... **** [[[[ \\\\
  343.  
  344.           (period, asterisk, left-bracket and backslash, respectively) lose
  345.           their special meaning within a bracket expression.
  346.  
  347.           The character sequences:
  348.  
  349.           [[[[.... [[[[==== [[[[::::
  350.  
  351.           (left-bracket followed by a period, equals-sign or colon) are
  352.           special inside a bracket expression and are used to delimit
  353.           collating symbols, equivalence class expressions and character class
  354.           expressions. These symbols must be followed by a valid expression
  355.           and the matching terminating sequence .], =] or :], as described in
  356.           the following items.
  357.  
  358.      2.   A _m_a_t_c_h_i_n_g _l_i_s_t expression specifies a list that matches any one of
  359.           the expressions represented in the list. The first character in the
  360.           list must not be the circumflex. For example, [abc] is an RE that
  361.           matches any of the characters a, b or c.
  362.  
  363.      3.   A _n_o_n-_m_a_t_c_h_i_n_g _l_i_s_t expression begins with a circumflex (^), and
  364.           specifies a list that matches any character or collating element
  365.           except for the expressions represented in the list after the leading
  366.           circumflex. For example, [^abc] is an RE that matches any character
  367.           or collating element except the characters a, b or c. The circumflex
  368.           will have this special meaning only when it occurs first in the
  369.           list, immediately following the left-bracket.
  370.  
  371.      4.   A _c_o_l_l_a_t_i_n_g _s_y_m_b_o_l is a collating element enclosed within bracket-
  372.           period ([. .]) delimiters. Collating elements are defined as
  373.           described in _cccc_oooo_llll_llll_tttt_bbbb_llll_((((_1111_MMMM_)))). Multi-character collating elements must be
  374.           represented as collating symbols when it is necessary to distinguish
  375.           them from a list of the individual characters that make up the
  376.           multi-character collating element.  For example, if the string ch is
  377.           a collating element in the current collation sequence with the
  378.           associated collating symbol <ch>, the expression [[.ch.]] will be
  379.           treated as an RE matching the character sequence ch, while [ch] will
  380.           be treated as an RE matching c or h.  Collating symbols will be
  381.           recognised only inside bracket expressions. This implies that the RE
  382.           [[.ch.]]*c matches the first to fifth character in the string
  383.           chchch. If the string is not a collating element in the current
  384.           collating sequence definition, or if the collating element has no
  385.           characters associated with it (for example, see the symbol <HIGH> in
  386.           the example collation definition shown in _cccc_oooo_llll_llll_tttt_bbbb_llll_((((_1111_MMMM_))))), the symbol
  387.           will be treated as an invalid expression.
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  401.  
  402.  
  403.  
  404.      5.   An _e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s _e_x_p_r_e_s_s_i_o_n represents the set of collating
  405.           elements belonging to an equivalence class, as described in
  406.           _cccc_oooo_llll_llll_tttt_bbbb_llll_((((_1111_MMMM_)))).  Only primary equivalence classes will be recognised.
  407.           The class is expressed by enclosing any one of the collating
  408.           elements in the equivalence class within bracket-equal ([= =])
  409.           delimiters.  For example, if a, agrave and acircumflex belong to the
  410.           same equivalence class, then [=a=]b], [[=agrave=]b] and
  411.           [[=acircumflex=]b] will each be equivalent to [aagraveacircumflexb].
  412.           If the collating element does not belong to an equivalence class,
  413.           the equivalence class expression will be treated as a _c_o_l_l_a_t_i_n_g
  414.           _s_y_m_b_o_l.
  415.  
  416.      6.   A _c_h_a_r_a_c_t_e_r _c_l_a_s_s _e_x_p_r_e_s_s_i_o_n represents the set of characters
  417.           belonging to a character class, as defined in the LC_CTYPE category
  418.           in the current locale. All character classes specified in the
  419.           current locale will be recognised. A character class expression is
  420.           expressed as a character class name enclosed within bracket-colon
  421.           ([: :]) delimiters.
  422.  
  423.           The following character class expressions are supported in all
  424.           locales:
  425.  
  426.  
  427.  
  428.           The following character class expressions are supported in all
  429.           locales:
  430.  
  431.                [:alnum:]     [:cntrl:]     [:lower:]     [:space:]
  432.                [:alpha:]     [:digit:]     [:print:]     [:upper:]
  433.                [:blank:]     [:graph:]     [:punct:]     [:xdigit:]
  434.  
  435.           In addition, character class expressions of the form:
  436.  
  437.                [:name:]
  438.  
  439.           are recognised in those locales where the _n_a_m_e keyword has been
  440.           given a _cccc_hhhh_aaaa_rrrr_cccc_llll_aaaa_ssss_ssss  definition in the LC_CTYPE category.
  441.  
  442.      7.   A _r_a_n_g_e _e_x_p_r_e_s_s_i_o_n represents the set of collating elements that
  443.           fall between two elements in the current collation sequence,
  444.           inclusively. It is expressed as the starting point and the ending
  445.           point separated by a hyphen (_----).
  446.  
  447.           Range expressions must not be used in portable applications because
  448.           their behaviour is dependent on the collating sequence. Ranges will
  449.           be treated according to the current collating sequence, and include
  450.           such characters that fall within the range based on that collating
  451.           sequence, regardless of character values. This, however, means that
  452.           the interpretation will differ depending on collating sequence. If,
  453.           for instance, one collating sequence defines _a_u_m_l_a_t as a variant of
  454.           a, while another defines it as a letter following z, then the
  455.           expression [_a_u_m_l_a_t-z]  is valid in the first language and invalid in
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  467.  
  468.  
  469.  
  470.           the second.
  471.  
  472.           In the following, all examples assume the collation sequence
  473.           specified for the POSIX locale, unless another collation sequence is
  474.           specifically defined.
  475.  
  476.           The starting range point and the ending range point must be a
  477.           collating element or collating symbol. An equivalence class
  478.           expression used as a starting or ending point of a range expression
  479.           produces unspecified results. An equivalence class can be used
  480.           portably within a bracket expression, but only outside the range.
  481.           For example, the unspecified expression [[=e=]-f] should be given as
  482.           [[=e=]e-f]. The ending range point must collate equal to or higher
  483.           than the starting range point; otherwise, the expression will be
  484.           treated as invalid. The order used is the order in which the
  485.           collating elements are specified in the current collation
  486.           definition. One-to-many mappings (see the description of _L_C__C_O_L_L_A_T_E
  487.           in _llll_oooo_cccc_aaaa_llll_eeee_((((_1111_))))) will not be performed. For example, assuming that the
  488.           character _e_s_z_e_t is is placed in the collation sequence after r and
  489.           s, but before t and that it maps to the sequence ss for collation
  490.           purposes, then the expression [r-s] matches only r and s, but the
  491.           expression [s-t] matches s, _e_s_z_e_t ot t.
  492.  
  493.           The interpretation of range expressions where the ending range point
  494.           is also the starting range point of a subsequent range expression
  495.           (for instance [a-m-o]) is undefined.
  496.  
  497.           The hyphen character will be treated as itself if it occurs first
  498.           (after an initial ^, if any) or last in the list, or as an ending
  499.           range point in a range expression. As examples, the expressions [-
  500.           ac] and [ac-] are equivalent and match any of the characters a, c or
  501.           -; [^-ac] and [^ac-] are equivalent and match any characters except
  502.           a, c or -; the expression [%- -] matches any of the characters
  503.           between % and - inclusive; the expression [- -@] matches any of the
  504.           characters between - and @ inclusive; and the expression [a- -@] is
  505.           invalid, because the letter a follows the symbol - in the POSIX
  506.           locale. To use a hyphen as the starting range point, it must either
  507.           come first in the bracket expression or be specified as a collating
  508.           symbol, for example: [][.-.]-0], which matches either a right
  509.           bracket or any character or collating element that collates between
  510.           hyphen and 0, inclusive.
  511.  
  512.           If a bracket expression must specify both - and ], the ] must be
  513.           placed first (after the ^, if any) and the - last within the bracket
  514.           expression.
  515.  
  516.           _BBBB_RRRR_EEEE_ssss _MMMM_aaaa_tttt_cccc_hhhh_iiii_nnnn_gggg _MMMM_uuuu_llll_tttt_iiii_pppp_llll_eeee _CCCC_hhhh_aaaa_rrrr_aaaa_cccc_tttt_eeee_rrrr_ssss
  517.  
  518.           The following rules can be used to construct BREs matching multiple
  519.           characters from BREs matching a single character:
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  533.  
  534.  
  535.  
  536.      1.   The concatenation of BREs matches the concatenation of the strings
  537.           matched by each component of the BRE.
  538.  
  539.      2.   A _s_u_b_e_x_p_r_e_s_s_i_o_n  can be defined within a BRE by enclosing it between
  540.           the character pairs \( and \) . Such a subexpression matches
  541.           whatever it would have matched without the \( and \), except that
  542.           anchoring within subexpressions is optional behaviour.
  543.           Subexpressions can be arbitrarily nested.
  544.  
  545.      3.   The _b_a_c_k-_r_e_f_e_r_e_n_c_e  expression \_n matches the same (possibly empty)
  546.           string of characters as was matched by a subexpression enclosed
  547.           between \( and \) preceding the \_n. The character n must be a digit
  548.           from 1 to 9 inclusive, _nth subexpression (the one that begins with
  549.           the _nth \( and ends with the corresponding paired \)).  The
  550.           expression is invalid if less than _n subexpressions precede the \_n.
  551.           For example, the expression ^\(.*\)\1$ matches a line consisting of
  552.           two adjacent appearances of the same string, and the expression
  553.           \(a\)*\1 fails to match _a. The limit of nine back-references to
  554.           subexpressions in the RE is based on the use of a single digit
  555.           identifier.  This does not imply that only nine subexpressions are
  556.           allowed in REs. The following is a valid BRE with ten
  557.           subexpressions:
  558.  
  559.      \(\(\(ab\)*c\)*d\)\(ef\)*\(gh\)\{2\}\(ij\)*\(kl\)*\(mn\)*\(op\)*\(qr\)*
  560.  
  561.  
  562.      4.   When a BRE matching a single character, a subexpression or a back-
  563.           reference is followed by the special character asterisk (*),
  564.           together with that asterisk it matches what zero or more consecutive
  565.           occurrences of the BRE would match. For example, [ab]* and [ab][ab]
  566.           are equivalent when matching the string ab.
  567.  
  568.      5.   When a BRE matching a single character, a subexpression or a back-
  569.           reference is followed by an _i_n_t_e_r_v_a_l _e_x_p_r_e_s_s_i_o_n of the format \{_m\},
  570.           \{_m,\} or \{_m,_n\}, together with that interval expression it matches
  571.           what repeated consecutive occurrences of the BRE would match. The
  572.           values of _m and _n will be decimal integers in the range 0 <= _m <= _n
  573.           <= _R_E__D_U_P__M_A_X, where _m specifies the exact or minimum number of
  574.           occurrences and _n specifies the maximum number of occurrences. The
  575.           expression \{_m\} matches exactly _m occurrences of the preceding BRE,
  576.           \{_m,\} matches at least _m occurrences and \{_m,_n\} matches any number
  577.           of occurrences between _m and _n, inclusive.
  578.  
  579.           For example, in the string abababccccccd the BRE c\{3\} is matched
  580.           by characters seven to nine, the BRE \(ab\)\{4,\} is not matched at
  581.           all and the BRE c\{1,3\}d is matched by characters ten to thirteen.
  582.  
  583.      The behaviour of multiple adjacent duplication symbols (_**** and intervals)
  584.      produces undefined results.
  585.  
  586.      _BBBB_RRRR_EEEE _PPPP_rrrr_eeee_cccc_eeee_dddd_eeee_nnnn_cccc_eeee
  587.  
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  599.  
  600.  
  601.  
  602.           The order of precedence is as shown in the following table:
  603.  
  604.           _B_R_E _P_r_e_c_e_d_e_n_c_e (_f_r_o_m _h_i_g_h _t_o _l_o_w)
  605.  
  606.                _c_o_l_l_a_t_i_o_n-_r_e_l_a_t_e_d _b_r_a_c_k_e_t _s_y_m_b_o_l_s   [= =]  [: :]  [. .]
  607.  
  608.                _e_s_c_a_p_e_d _c_h_a_r_a_c_t_e_r_s                  \<_s_p_e_c_i_a_l _c_h_a_r_a_c_t_e_r>
  609.  
  610.                _b_r_a_c_k_e_t _e_x_p_r_e_s_s_i_o_n                  []
  611.  
  612.                _s_u_b_e_x_p_r_e_s_s_i_o_n_s/_b_a_c_k-_r_e_f_e_r_e_n_c_e_s      \(\)\_n
  613.  
  614.                _s_i_n_g_l_e-_c_h_a_r_a_c_t_e_r-_B_R_E _d_u_p_l_i_c_a_t_i_o_n    *\{_m,_n\}
  615.  
  616.                _c_o_n_c_a_t_e_n_a_t_i_o_n
  617.  
  618.                _a_n_c_h_o_r_i_n_g                           ^ $
  619.  
  620.      _BBBB_RRRR_EEEE _EEEE_xxxx_pppp_rrrr_eeee_ssss_ssss_iiii_oooo_nnnn _AAAA_nnnn_cccc_hhhh_oooo_rrrr_iiii_nnnn_gggg
  621.  
  622.           A BRE can be limited to matching strings that begin or end a line;
  623.           this is called _a_n_c_h_o_r_i_n_g.  The circumflex and dollar sign special
  624.           characters will be considered BRE anchors in the following contexts:
  625.  
  626.  
  627.      1.   A circumflex (_^^^^) is an anchor when used as the first character of an
  628.           entire BRE. The implementation may treat circumflex as an anchor
  629.           when used as the first character of a subexpression. The circumflex
  630.           will anchor the expression (or optionally subexpression) to the
  631.           beginning of a string; only sequences starting at the first
  632.           character of a string will be matched by the BRE. For example, the
  633.           BRE ^ab matches ab in the string abcdef, but fails to match in the
  634.           string cdefab. The BRE \(^ab\) may match the former string.  A
  635.           portable BRE must escape a leading circumflex in a subexpression to
  636.           match a literal circumflex.
  637.  
  638.      2.   A dollar sign (_$$$$) is an anchor when used as the last character of an
  639.           entire BRE. The implementation may treat a dollar sign as an anchor
  640.           when used as the last character of a subexpression.  The dollar sign
  641.           will anchor the expression (or optionally subexpression) to the end
  642.           of the string being matched; the dollar sign can be said to match
  643.           the end-of-string following the last character.
  644.  
  645.      3.   A BRE anchored by both _^^^^ and _$$$$ matches only an entire string. For
  646.           example, the BRE ^abcdef$ matches strings consisting only of abcdef.
  647.  
  648.      _EEEE_xxxx_tttt_eeee_nnnn_dddd_eeee_dddd _RRRR_eeee_gggg_uuuu_llll_aaaa_rrrr _EEEE_xxxx_pppp_rrrr_eeee_ssss_ssss_iiii_oooo_nnnn_ssss
  649.  
  650.           The _e_x_t_e_n_d_e_d _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n (ERE) notation and construction
  651.           rules will apply to utilities defined as using extended regular
  652.           expressions; any exceptions to the following rules are noted in the
  653.           descriptions of the specific utilities using EREs.
  654.  
  655.  
  656.  
  657.                                                                        PPPPaaaaggggeeee 11110000
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  665.  
  666.  
  667.  
  668.      _EEEE_RRRR_EEEE_ssss _MMMM_aaaa_tttt_cccc_hhhh_iiii_nnnn_gggg _aaaa _SSSS_iiii_nnnn_gggg_llll_eeee _CCCC_hhhh_aaaa_rrrr_aaaa_cccc_tttt_eeee_rrrr _oooo_rrrr _CCCC_oooo_llll_llll_aaaa_tttt_iiii_nnnn_gggg _EEEE_llll_eeee_mmmm_eeee_nnnn_tttt
  669.  
  670.           An ERE ordinary character, a special character preceded by a
  671.           backslash or a period matches a single character.  A bracket
  672.           expression matches a single character or a single collating element.
  673.           An _E_R_E _m_a_t_c_h_i_n_g _a _s_i_n_g_l_e _c_h_a_r_a_c_t_e_r enclosed in parentheses matches
  674.           the same as the ERE without parentheses would have matched.
  675.  
  676.      _EEEE_RRRR_EEEE _OOOO_rrrr_dddd_iiii_nnnn_aaaa_rrrr_yyyy _CCCC_hhhh_aaaa_rrrr_aaaa_cccc_tttt_eeee_rrrr_ssss
  677.  
  678.           An _o_r_d_i_n_a_r_y _c_h_a_r_a_c_t_e_r  is an ERE that matches itself.  An ordinary
  679.           character is any character in the supported character set, except
  680.           for the ERE special characters listed in _eeee_rrrr_eeee_ssss_pppp_eeee_cccc.  The
  681.           interpretation of an ordinary character preceded by a backslash (_\\\\)
  682.           is undefined.
  683.  
  684.      _EEEE_RRRR_EEEE _SSSS_pppp_eeee_cccc_iiii_aaaa_llll _CCCC_hhhh_aaaa_rrrr_aaaa_cccc_tttt_eeee_rrrr_ssss
  685.  
  686.           An _E_R_E _s_p_e_c_i_a_l _c_h_a_r_a_c_t_e_r has special properties in certain contexts.
  687.           Outside those contexts, or when preceded by a backslash, such a
  688.           character is an ERE that matches the special character itself.  The
  689.           extended regular expression special characters and the contexts in
  690.           which they have their special meaning are:
  691.  
  692.  
  693.      .... [[[[ \\\\ ((((
  694.           The period, left-bracket, backslash and left-parenthesis are special
  695.           except when used in a bracket expression.  Outside a bracket
  696.           expression, a left-parenthesis immediately followed by a right-
  697.           parenthesis produces undefined results.
  698.  
  699.      ))))    The right-parenthesis is special when matched with a preceding
  700.           left-parenthesis, both outside a bracket expression.
  701.  
  702.      **** ++++ ???? {{{{
  703.           The asterisk, plus-sign, question-mark and left-brace are special
  704.           except when used in a bracket expression.  Any of the following uses
  705.           produce undefined results:
  706.  
  707.                if these characters appear first in an ERE, or immediately
  708.                following a vertical-line, circumflex or left-parenthesis
  709.  
  710.                if a left-brace is not part of a valid interval expression.
  711.  
  712.      ||||    The vertical-line is special except when used in a bracket
  713.           expression.  A vertical-line appearing first or last in an ERE, or
  714.           immediately following a vertical-line or a left-parenthesis, or
  715.           immediately preceding a right-parenthesis, produces undefined
  716.           results.
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                                                        PPPPaaaaggggeeee 11111111
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  731.  
  732.  
  733.  
  734.      ^^^^    The circumflex is special when used:
  735.  
  736.                as an anchor
  737.  
  738.                as the first character of a bracket expression.
  739.  
  740.      $$$$    The dollar sign is special when used as an anchor.
  741.  
  742.      _PPPP_eeee_rrrr_iiii_oooo_dddd_ssss _iiii_nnnn _EEEE_RRRR_EEEE_ssss
  743.  
  744.           A period (_....), when used outside a bracket expression, is an ERE that
  745.           matches any character in the supported character set except NUL.
  746.  
  747.      _EEEE_RRRR_EEEE_ssss _MMMM_aaaa_tttt_cccc_hhhh_iiii_nnnn_gggg _MMMM_uuuu_llll_tttt_iiii_pppp_llll_eeee _CCCC_hhhh_aaaa_rrrr_aaaa_cccc_tttt_eeee_rrrr_ssss
  748.  
  749.           The following rules will be used to construct EREs matching multiple
  750.           characters from EREs matching a single character:
  751.  
  752.      1.   A _c_o_n_c_a_t_e_n_a_t_i_o_n _o_f _E_R_E_s matches the concatenation of the character
  753.           sequences matched by each component of the ERE. A concatenation of
  754.           EREs enclosed in parentheses matches whatever the concatenation
  755.           without the parentheses matches. For example, both the ERE cd and
  756.           the ERE (cd) are matched by the third and fourth character of the
  757.           string abcdefabcdef.
  758.  
  759.      2.   When an ERE matching a single character or an ERE enclosed in
  760.           parentheses is followed by the special character plus-sign (+),
  761.           together with that plus-sign it matches what one or more consecutive
  762.           occurrences of the ERE would match. For example, the ERE b+(bc)
  763.           matches the fourth to seventh characters in the string acabbbcde.
  764.           And, [ab]+ and [ab][ab]* are equivalent.
  765.  
  766.      3.   When an ERE matching a single character or an ERE enclosed in
  767.           parentheses is followed by the special character asterisk (_****),
  768.           together with that asterisk it matches what zero or more consecutive
  769.           occurrences of the ERE would match.  For example, the ERE b*c
  770.           matches the first character in the string cabbbcde, and the ERE b*cd
  771.           matches the third to seventh characters in the string
  772.           cabbbcdebbbbbbcdbc. And, [ab]* and [ab][ab] are equivalent when
  773.           matching the string ab.
  774.  
  775.      4.   When an ERE matching a single character or an ERE enclosed in
  776.           parentheses is followed by the special character question-mark (_????),
  777.           together with that question-mark it matches what zero or one
  778.           consecutive occurrences of the ERE would match. For example, the ERE
  779.           b?c matches the second character in the string acabbbcde.
  780.  
  781.      5.   When an ERE matching a single character or an ERE enclosed in
  782.           parentheses is followed by an _i_n_t_e_r_v_a_l _e_x_p_r_e_s_s_i_o_n of the format {_m},
  783.           {_m,} or {_m,_n}, together with that interval expression it matches
  784.           what repeated consecutive occurrences of the ERE would match.  The
  785.           values of _m and  _n will be decimal integers in the range 0 <= _m <= _n
  786.  
  787.  
  788.  
  789.                                                                        PPPPaaaaggggeeee 11112222
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  797.  
  798.  
  799.  
  800.           <= _R_E__D_U_P__M_A_X, where _m specifies the exact or minimum number of
  801.           occurrences and _n specifies the maximum number of occurrences. The
  802.           expression {_m} matches exactly _m occurrences of the preceding ERE,
  803.           {_m,} matches at least _m occurrences and {_m,_n} matches any number of
  804.           occurrences between _m and _n, inclusive.  For example, in the string
  805.           abababccccccd the ERE c{3} is matched by characters seven to nine
  806.           and the ERE (ab){2,} is matched by characters one to six.
  807.  
  808.      The behaviour of multiple adjacent duplication symbols (_++++_,,,, _****_,,,, _???? and
  809.      intervals) produces undefined results.
  810.  
  811.      _EEEE_RRRR_EEEE _AAAA_llll_tttt_eeee_rrrr_nnnn_aaaa_tttt_iiii_oooo_nnnn
  812.  
  813.           Two EREs separated by the special character vertical-line (|) match
  814.           a string that is matched by either. For example, the ERE a((bc)|d)
  815.           matches the string abc and the string ad. Single characters, or
  816.           expressions matching single characters, separated by the vertical
  817.           bar and enclosed in parentheses, will be treated as an ERE matching
  818.           a single character.
  819.  
  820.      _EEEE_RRRR_EEEE _PPPP_rrrr_eeee_cccc_eeee_dddd_eeee_nnnn_cccc_eeee
  821.  
  822.           The order of precedence is as shown in the following table:
  823.  
  824.           _B_R_E _P_r_e_c_e_d_e_n_c_e (_f_r_o_m _h_i_g_h _t_o _l_o_w)
  825.  
  826.                _c_o_l_l_a_t_i_o_n-_r_e_l_a_t_e_d _b_r_a_c_k_e_t _s_y_m_b_o_l_s   [= =]  [: :]  [. .]
  827.  
  828.                _e_s_c_a_p_e_d _c_h_a_r_a_c_t_e_r_s                  \<_s_p_e_c_i_a_l _c_h_a_r_a_c_t_e_r>
  829.  
  830.                _b_r_a_c_k_e_t _e_x_p_r_e_s_s_i_o_n                  []
  831.  
  832.                _g_r_o_u_p_i_n_g                            ()
  833.  
  834.                _s_i_n_g_l_e-_c_h_a_r_a_c_t_e_r-_E_R_E _d_u_p_l_i_c_a_t_i_o_n    *+?{_m,_n}
  835.  
  836.                _c_o_n_c_a_t_e_n_a_t_i_o_n
  837.  
  838.                _a_n_c_h_o_r_i_n_g                           ^ $
  839.  
  840.                _a_l_t_e_r_a_t_i_o_n                          |
  841.  
  842.      For example, the ERE abba | cde matches either the string abba or the
  843.      string cde (rather than the string abbade or abbcde, because
  844.      concatenation has a higher order of precedence than alternation).
  845.  
  846.      _EEEE_RRRR_EEEE _EEEE_xxxx_pppp_rrrr_eeee_ssss_ssss_iiii_oooo_nnnn _AAAA_nnnn_cccc_hhhh_oooo_rrrr_iiii_nnnn_gggg
  847.  
  848.           An ERE can be limited to matching strings that begin or end a line;
  849.           this is called _a_n_c_h_o_r_i_n_g.  The circumflex and dollar sign special
  850.           characters are considered ERE anchors when used anywhere outside a
  851.           bracket expression. This has the following effects:
  852.  
  853.  
  854.  
  855.                                                                        PPPPaaaaggggeeee 11113333
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  863.  
  864.  
  865.  
  866.      1.   A circumflex (_^^^^) outside a bracket expression anchors the expression
  867.           or subexpression it begins to the beginning of a string; such an
  868.           expression or subexpression can match only a sequence starting at
  869.           the first character of a string. For example, the EREs ^ab and (^ab)
  870.           match ab in the string abcdef, but fail to match in the string
  871.           cdefab, and the ERE a^b is valid, but can never match because the _a
  872.           prevents the expression ^b from matching starting at the first
  873.           character.
  874.  
  875.      2.   A dollar sign (_$$$$) outside a bracket expression anchors the
  876.           expression or subexpression it ends to the end of a string; such an
  877.           expression or subexpression can match only a sequence ending at the
  878.           last character of a string. For example, the EREs ef$ and (ef$)
  879.           match ef in the string abcdef, but fail to match in the string
  880.           cdefab, and the ERE e$f is valid, but can never match because the _f
  881.           prevents the expression e$ from matching ending at the last
  882.           character.
  883.  
  884.      _RRRR_eeee_gggg_uuuu_llll_aaaa_rrrr _EEEE_xxxx_pppp_rrrr_eeee_ssss_ssss_iiii_oooo_nnnn _GGGG_rrrr_aaaa_mmmm_mmmm_aaaa_rrrr
  885.  
  886.           Grammars describing the syntax of both basic and extended regular
  887.           expressions are presented in this section. The grammar takes
  888.           precedence over the text.
  889.  
  890.      _BBBB_RRRR_EEEE_////_EEEE_RRRR_EEEE _GGGG_rrrr_aaaa_mmmm_mmmm_aaaa_rrrr _LLLL_eeee_xxxx_iiii_cccc_aaaa_llll _CCCC_oooo_nnnn_vvvv_eeee_nnnn_tttt_iiii_oooo_nnnn_ssss
  891.  
  892.           The lexical conventions for regular expressions are as described in
  893.           this section.
  894.  
  895.           Except as noted, the longest possible token or delimiter beginning
  896.           at a given point will be recognised.
  897.  
  898.           The following tokens will be processed (in addition to those string
  899.           constants shown in the grammar):
  900.  
  901.  
  902.      CCCCOOOOLLLLLLLL____EEEELLLLEEEEMMMM      Any single-character collating element, unless it is a
  903.                     META_CHAR.
  904.  
  905.      BBBBAAAACCCCKKKKRRRREEEEFFFF        Applicable only to basic regular expressions. The
  906.                     character string consisting of _\\\\ followed by a single-
  907.                     digit numeral, 1 to 9.
  908.  
  909.      DDDDUUUUPPPP____CCCCOOOOUUUUNNNNTTTT      Represents a numeric constant. It is an integer in the
  910.                     range 0 <= _D_U_P__C_O_U_N_T <= _R_E__D_U_P__M_A_X. This token will only
  911.                     be recognised when the context of the grammar requires it.
  912.                     At all other times, digits not preceded by _\\\\ will be
  913.                     treated as ORD_CHAR.
  914.  
  915.      MMMMEEEETTTTAAAA____CCCCHHHHAAAARRRR      One of the characters:
  916.  
  917.                          _^^^^   when found first in a bracket expression
  918.  
  919.  
  920.  
  921.                                                                        PPPPaaaaggggeeee 11114444
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  929.  
  930.  
  931.  
  932.                          _----   when found anywhere but first (after an initial
  933.                              _^^^^, if any) or last in a bracket expression, or as
  934.                              the ending
  935.                              range point in a range expression
  936.  
  937.                          _]]]]   when found anywhere but first (after an initial
  938.                              _^^^^, if any) in a bracket expression.
  939.  
  940.      LLLL____AAAANNNNCCCCHHHHOOOORRRR       Applicable only to basic regular expressions. The
  941.                     character _^^^^ when it appears as the first character of a
  942.                     basic regular expression and when not QUOTED_CHAR. The _^^^^
  943.                     may be recognised as an anchor elsewhere.
  944.  
  945.      OOOORRRRDDDD____CCCCHHHHAAAARRRR       A character, other than one of the special characters in
  946.                     SPEC_CHAR.
  947.  
  948.      QQQQUUUUOOOOTTTTEEEEDDDD____CCCCHHHHAAAARRRR    In a BRE, one of the character sequences:
  949.  
  950.                     \^      \.      \*      \[      \$      \\
  951.  
  952.                     In an ERE, one of the character sequences:
  953.  
  954.                     \^   \.   \[   \$   \(   \)  \|  \*   \+   \?   \{   \\
  955.  
  956.      RRRR____AAAANNNNCCCCHHHHOOOORRRR       (Applicable only to basic regular expressions.) The
  957.                     character _$$$$ when it appears as the last character of a
  958.                     basic regular expression and when not QUOTED_CHAR. The _$$$$
  959.                     may be recognised as an anchor elsewhere.
  960.  
  961.      SSSSPPPPEEEECCCC____CCCCHHHHAAAARRRR      For basic regular expressions, will be one of the
  962.                     following special characters:
  963.  
  964.  
  965.                     _\\\\  anywhere outside bracket expressions
  966.  
  967.                     _[[[[   anywhere outside bracket expressions
  968.  
  969.                     _^^^^   when used as an anchor or when
  970.                         first in a bracket expression
  971.  
  972.                     _$$$$   when used as an anchor
  973.  
  974.                     _****   anywhere except: first in an entire RE;
  975.                         anywhere in a bracket expression; directly
  976.                         following \(; directly following an
  977.                         anchoring _^^^^.
  978.  
  979.                     For extended regular expressions, will be one of the
  980.                     following special characters found anywhere outside
  981.                     bracket expressions:
  982.  
  983.                     ^    .    [    $    (    )    |    *    +    ?    {    \
  984.  
  985.  
  986.  
  987.                                                                        PPPPaaaaggggeeee 11115555
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  995.  
  996.  
  997.  
  998.                     (The close-parenthesis is considered special in this
  999.                     context only if matched with a preceding open-
  1000.                     parenthesis.)
  1001.  
  1002.  
  1003. RRRREEEE aaaannnndddd BBBBrrrraaaacccckkkkeeeetttt EEEExxxxpppprrrreeeessssssssiiiioooonnnn GGGGrrrraaaammmmmmmmaaaarrrr
  1004.      This section presents the grammar for basic regular expressions,
  1005.      including the bracket expression grammar that is common to both BREs and
  1006.      EREs.
  1007.  
  1008.      %token ORD_CHAR QUOTED_CHAR DUP_COUNT
  1009.      %token BACKREF L_ANCHOR R_ANCHOR
  1010.      %token Back_open_paren  Back_close_paren
  1011.      /*    '\('              '\)'                     */
  1012.      %token Back_open_brace  Back_close_brace
  1013.      /*    '\{'              '\}'                     */
  1014.      /* The following tokens are for the Bracket Expression
  1015.         grammar common to both REs and EREs.              */
  1016.      %token COLL_ELEM META_CHAR
  1017.      %token Open_equal Equal_close Open_dot Dot_close Open_colon Colon_close
  1018.      /*    '[='         '=]'      '[.'    '.]'       '[:'        ':]'  */
  1019.      %token class_name
  1020.      /* class_name is a keyword to the LC_CTYPE locale category */
  1021.      /* (representing a character class) in the current locale  */
  1022.      /* and is only recognised between [: and :]                */
  1023.      %start basic_reg_exp
  1024.      %%
  1025.      /*             --------------------------------------------
  1026.                     Basic Regular Expression
  1027.                     --------------------------------------------
  1028.      */
  1029.      basic_reg_exp :          RE_expression
  1030.                    | L_ANCHOR
  1031.                    |                        R_ANCHOR
  1032.                    | L_ANCHOR               R_ANCHOR
  1033.                    | L_ANCHOR RE_expression
  1034.                    |          RE_expression R_ANCHOR
  1035.                    | L_ANCHOR RE_expression R_ANCHOR
  1036.                    ;
  1037.  
  1038.      RE_expression :               simple_RE
  1039.                    | RE_expression simple_RE
  1040.                    ;
  1041.  
  1042.      simple_RE     : nondupl_RE
  1043.                    | nondupl_RE RE_dupl_symbol
  1044.                    ;
  1045.  
  1046.      nondupl_RE    : one_character_RE
  1047.                    | Back_open_paren RE_expression Back_close_paren
  1048.                    | Back_open_paren Back_close_paren
  1049.                    | BACKREF
  1050.  
  1051.  
  1052.  
  1053.                                                                        PPPPaaaaggggeeee 11116666
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  1061.  
  1062.  
  1063.  
  1064.                    ;
  1065.  
  1066.      one_character_RE : ORD_CHAR
  1067.                       | QUOTED_CHAR
  1068.                       | '.'
  1069.                       | bracket_expression
  1070.                       ;
  1071.  
  1072.      RE_dupl_symbol : '*'
  1073.                     | Back_open_brace DUP_COUNT               Back_close_brace
  1074.                     | Back_open_brace DUP_COUNT ','           Back_close_brace
  1075.                     | Back_open_brace DUP_COUNT ',' DUP_COUNT Back_close_brace
  1076.                     ;
  1077.  
  1078.      /*                 --------------------------------------------
  1079.                         Bracket Expression
  1080.                         -------------------------------------------
  1081.      */
  1082.      bracket_expression : '[' matching_list    ']'
  1083.                         | '[' nonmatching_list ']'
  1084.                         ;
  1085.  
  1086.      matching_list      : bracket_list
  1087.                         ;
  1088.  
  1089.      nonmatching_list   : '^' bracket_list
  1090.                         ;
  1091.  
  1092.      bracket_list       : follow_list
  1093.                         | follow_list '-'
  1094.                         ;
  1095.  
  1096.      follow_list        :             expression_term
  1097.                         | follow_list expression_term
  1098.                         ;
  1099.  
  1100.      expression_term    : single_expression
  1101.                         | range_expression
  1102.                         ;
  1103.  
  1104.      single_expression  : end_range
  1105.                         | character_class
  1106.                         | equivalence_class
  1107.                         ;
  1108.  
  1109.      range_expression   : start_range end_range
  1110.                         | start_range '-'
  1111.                         ;
  1112.  
  1113.      start_range        : end_range '-'
  1114.                         ;
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                                                        PPPPaaaaggggeeee 11117777
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  1127.  
  1128.  
  1129.  
  1130.      end_range          : COLL_ELEM
  1131.                         | collating_symbol
  1132.                         ;
  1133.  
  1134.      collating_symbol   : Open_dot COLL_ELEM Dot_close
  1135.                         | Open_dot META_CHAR Dot_close
  1136.                         ;
  1137.  
  1138.      equivalence_class  : Open_equal COLL_ELEM Equal_close
  1139.                         ;
  1140.  
  1141.      character_class    : Open_colon class_name Colon_close
  1142.                         ;
  1143.  
  1144.      The BRE grammar does not permit L_ANCHOR or R_ANCHOR inside \( and \)
  1145.      (which implies that ^ and $ are ordinary characters).
  1146.  
  1147.  
  1148. EEEERRRREEEE GGGGrrrraaaammmmmmmmaaaarrrr
  1149.      This section presents the grammar for extended regular expressions,
  1150.      excluding the bracket expression grammar.
  1151.  
  1152.      _NNNN_oooo_tttt_eeee_::::  The bracket expression grammar and the associated _%%%%_tttt_oooo_kkkk_eeee_nnnn
  1153.             lines are identical between BREs and EREs. It has been omitted
  1154.             from the ERE section to avoid unnecessary editorial duplication.
  1155.  
  1156.      %token ORD_CHAR QUOTED_CHAR DUP_COUNT
  1157.      %start extended_reg_exp
  1158.      %%
  1159.      /*               --------------------------------------------
  1160.                       Extended Regular Expression
  1161.                       --------------------------------------------
  1162.      */
  1163.  
  1164.      extended_reg_exp :                      ERE_branch
  1165.                       | extended_reg_exp ' | ' ERE_branch
  1166.                       ;
  1167.  
  1168.      ERE_branch       :            ERE_expression
  1169.                       | ERE_branch ERE_expression
  1170.                       ;
  1171.  
  1172.      ERE_expression   : one_character_ERE
  1173.                       | '^'
  1174.                       | '$'
  1175.                       | '(' extended_reg_exp ')'
  1176.                       | ERE_expression ERE_dupl_symbol
  1177.                       ;
  1178.  
  1179.      one_character_ERE : ORD_CHAR
  1180.                        | QUOTED_CHAR
  1181.                        | '.'
  1182.  
  1183.  
  1184.  
  1185.                                                                        PPPPaaaaggggeeee 11118888
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192. RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))                                                          RRRREEEEGGGGCCCCOOOOMMMMPPPP((((5555))))
  1193.  
  1194.  
  1195.  
  1196.                        | bracket_expression
  1197.                        ;
  1198.  
  1199.      ERE_dupl_symbol  : '*'
  1200.                       | '+'
  1201.                       | '?'
  1202.                       | '{' DUP_COUNT               '}'
  1203.                       | '{' DUP_COUNT ','           '}'
  1204.                       | '{' DUP_COUNT ',' DUP_COUNT '}'
  1205.                       ;
  1206.  
  1207.      The ERE grammar does not permit several constructs that previous sections
  1208.      specify as having undefined results:
  1209.  
  1210.      o   ORD_CHAR preceded by \
  1211.  
  1212.      o   one or more ERE_dupl_symbols appearing first in an ERE,
  1213.          or immediately following _||||, _^^^^ or _((((
  1214.  
  1215.      o   _{{{{ not part of a valid ERE_dupl_symbol
  1216.  
  1217.      o   _|||| appearing first or last in an ERE,
  1218.          or immediately following _|||| or
  1219.          _((((, or immediately preceding _)))).
  1220.  
  1221.      Implementations are permitted to extend the language to allow these.
  1222.      Portable applications cannot use such constructs.
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                                                        PPPPaaaaggggeeee 11119999
  1252.  
  1253.  
  1254.  
  1255.